package com.aier.user.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.common.common.CommonSession;
import com.aier.common.common.Constant;
import com.aier.common.common.ICommonDAO;
import com.aier.user.entity.User;
import com.aier.user.service.IMyFansService;
import com.aier.user.service.IUserMessageService;

@Scope("prototype")
@Component("userMyFansAction")
public class UserMyFansAction extends UserBaseAction{

    /**
     * 粉丝
     */
	
    private static final long serialVersionUID = 1L;
    
    @Resource(name="myFansService")
    private IMyFansService myFansService;
    @Resource(name="userMessageService")
    private IUserMessageService userMessageService;
    
    // 错误码
    private int s;
    // 当前页数
    private int page;
    // 每页的记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总条数
    private int count;
    
    // 排序字段
    private String sort;
    
    // 粉丝列表
    List<User> userList;
    
    // 粉丝的用户id
    private Long fuid;
    // 关注状态：1已关注；2互相关注;0全部
    private Short state;
    
    // 访问其他人主页时
    private Long in_uid;
    
    @Override
    public String execute(){
        s = 1;
        return SUCCESS;
    }
    
    /**
     * 获取粉丝列表
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchFansList() {
        if (page <= 0) {
            page = 1;
        }
        if (page_size <= 0) {
            page_size = Constant.num_10;
        }
        
        Map<String, Object> map = null;
        if (null != in_uid) {
            map = myFansService.searchFansList(page, page_size, in_uid,sort,state);
        } else {
            
            map = myFansService.searchFansList(page, page_size, 
                    (Long) request.getSession().getAttribute(CommonSession.SESSION_ACCOUNT_ID),sort,state);
        }
        
        if (null != map) {
            page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
            count = (Integer)map.get(ICommonDAO.COUNT);
            page = (Integer)map.get(ICommonDAO.PAGE);
            
            userList = (List<User>) map.get(ICommonDAO.OBJ_LIST);
                
        }
        // 新增或修改用户查询粉丝的记录
        userMessageService.insertAction((Long) request.getSession().getAttribute(CommonSession.SESSION_ACCOUNT_ID),(short)1);
        
        s = 1;
        return SUCCESS;
    }
    
    /**
     * 移除粉丝
     * @return
     */
    public String deleteFans() {
        s = myFansService.deleteFans((Long) request.getSession().getAttribute(CommonSession.SESSION_ACCOUNT_ID), fuid, state);
        return SUCCESS;
    }


    public int getS() {
        return s;
    }


    public void setPage(int page) {
        this.page = page;
    }


    public void setPage_size(int page_size) {
        this.page_size = page_size;
    }

    public void setMyFansService(IMyFansService myFansService) {
        this.myFansService = myFansService;
    }

    public List<User> getUserList() {
        return userList;
    }

    public int getCount() {
        return count;
    }

    public void setFuid(Long fuid) {
        this.fuid = fuid;
    }

    public void setState(Short state) {
        this.state = state;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public int getPage_count() {
        return page_count;
    }

    public void setIn_uid(Long in_uid) {
        this.in_uid = in_uid;
    }

    public int getPage() {
        return page;
    }

    public void setUserMessageService(IUserMessageService userMessageService) {
        this.userMessageService = userMessageService;
    }

}
